package model;

import java.util.List;

import javax.ejb.Local;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

@Stateless
@Local(UserService.class)
@TransactionAttribute(TransactionAttributeType.NEVER)
public class UserServiceBean implements UserService {

	@PersistenceContext
	EntityManager em;

	@Override
	public void create(User t) {
		em.persist(t);
		em.flush();
		em.refresh(t);
	}

	@Override
	public void delete(int id) {
		em.remove(getUser(id));
	}
	
	@Override
	public void update(User t) {
		em.merge(t);
	}

	@Override
	public User getUser(int id) {
		return em.find(User.class, id);
	}


	@Override
	public List<User> getAllUsers() {

		return em.createNamedQuery("Users.getAll").getResultList();
		
	}

	@Override
	public User autentificateUser(String name, String password) {

		return null;
	}
}